﻿using System;
using System.Collections.Generic;

namespace Framework.Core.Queue
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TValue"></typeparam>
    /// <typeparam name="TStatus"></typeparam>
    public interface IStatusQueue<TKey, TValue, TStatus>
    {

        object SyncObj
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        event NewQueuerInQueueHandler<TKey, TValue, TStatus> OnNewQueuerInQueue;
        /// <summary>
        /// 
        /// </summary>
        event QueuerOutQueueHandler<TKey, TValue, TStatus> OnQueuerOutQueue;
        /// <summary>
        /// 
        /// </summary>
        IDictionary<TKey, IStatusQueuer<TKey, TValue, TStatus>> Queuers { get; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="status"></param>
        IStatusQueuer<TKey, TValue, TStatus> Add(TKey key, TValue value, TStatus status);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="queuer"></param>
        IStatusQueuer<TKey, TValue, TStatus> Add(IStatusQueuer<TKey, TValue, TStatus> queuer);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool ContainsKey(TKey key);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool Remove(TKey key);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        IStatusQueuer<TKey, TValue, TStatus> this[TKey key] { get; }

        #region GetTopNQueuers
        /// <summary>
        /// 得到一定数量前N个队列成员
        /// </summary>
        /// <param name="count">数量</param>
        /// <returns></returns>
        IList<IStatusQueuer<TKey, TValue, TStatus>> GetTopNQueuers(int count);
        /// <summary>
        /// 得到一定数量、在某些状态范围中的前N个队列成员
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="statuses">状态范围</param>
        /// <returns></returns>
        IList<IStatusQueuer<TKey, TValue, TStatus>> GetTopNQueuers(int count, IList<TStatus> statuses);
        /// <summary>
        /// 得到一定数量、在某些状态范围中、最后访问时间大于某一间隔的前N个队列成员
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="statuses">状态范围</param>
        /// <param name="lastQueryTimeSpan">时间间隔</param>
        /// <returns></returns>
        IList<IStatusQueuer<TKey, TValue, TStatus>> GetTopNQueuers(int count, IList<TStatus> statuses, TimeSpan lastQueryTimeSpan);
        #endregion

        #region GetTopNQueuers
        /// <summary>
        /// 
        /// </summary>
        /// <param name="timeOutTimeSpan"></param>
        /// <returns></returns>
        IList<IStatusQueuer<TKey, TValue, TStatus>> GetTimeOutQueuers(TimeSpan timeOutTimeSpan);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="count"></param>
        /// <param name="timeOutTimeSpan"></param>
        /// <returns></returns>
        IList<IStatusQueuer<TKey, TValue, TStatus>> GetTimeOutQueuers(int count, TimeSpan timeOutTimeSpan);
        #endregion
    }
}